package hexapawn.ai;

import java.util.LinkedList;
import java.util.List;

import hexapawn.game.Board;
import hexapawn.game.Cell;
import hexapawn.game.Player;

public class MDPPlayer extends Player{

	public MDPPlayer(Board _board) {
		super(_board, Player.PLAYER_MDP);
	}

	@Override
	protected void removeTarget(Cell target) {
		Player other = board.getBottomPlayer();
		other.getPieces().remove(target.getPiece());
	}
	
	/**
	 * This should be modified to w/e MDP AI do to make a move.
	 * 
	 */
	@Override
	public void makeMove(Cell to){
		
	}

	@Override
	public List<Cell> getPossibleMoves(Cell _from) {
		List<Cell> possibleMoves = new LinkedList<Cell>();
		from = _from;
		int row = from.getRow();
		int col = from.getColumn();
		if(row+1 < board.getRow()){
			Cell below, belowLeft, belowRight;
			below = board.getCellBelow(from);
			if(!below.hasPiece()) possibleMoves.add(below);
			if(col-1 >= 0){
				belowLeft = board.getCellBelowLeft(from);
				if(belowLeft.hasPiece())
					if(belowLeft.getPiece().getOwner() == PLAYER_MINIMAX) possibleMoves.add(belowLeft);
			}
			if(col+1 < board.getColumn()){
				belowRight = board.getCellBelowRight(from);
				if(belowRight.hasPiece())
					if(belowRight.getPiece().getOwner() == PLAYER_MINIMAX) possibleMoves.add(belowRight);
			}
		}
		if(possibleMoves.size() == 0) from = null;
		return possibleMoves;
	}
	
	public List<Cell> getPossibleMoves(Board b, Cell _from) {
		List<Cell> possibleMoves = new LinkedList<Cell>();
		from = _from;
		int row = from.getRow();
		int col = from.getColumn();
		if(row+1 < b.getRow()){
			Cell below, belowLeft, belowRight;
			below = b.getCellBelow(from);
			if(!below.hasPiece()) possibleMoves.add(below);
			if(col-1 >= 0){
				belowLeft = b.getCellBelowLeft(from);
				if(belowLeft.hasPiece())
					if(belowLeft.getPiece().getOwner() == PLAYER_MINIMAX) possibleMoves.add(belowLeft);
			}
			if(col+1 < b.getColumn()){
				belowRight = b.getCellBelowRight(from);
				if(belowRight.hasPiece())
					if(belowRight.getPiece().getOwner() == PLAYER_MINIMAX) possibleMoves.add(belowRight);
			}
		}
		if(possibleMoves.size() == 0) from = null;
		return possibleMoves;
	}

}
